<?php
	namespace Dashboard\Controller;
	use Think\Controller;
    use Think\Verify;
	class LoginController extends Controller {
        public function __construct() {
            parent::__construct();
            $this->verify=new Verify();
        }
	    public function index(){
            $name = "医美 ";
            $this->assign("nn",$name);
	    	$this->display();
	    }
	    public function login(){
	        //验证码检测
            $checkpwd = $_POST['token'];//表单提交的用户输入的验证码
            $code     = new Verify(array('reset'=>false));
            $cd       = $code->check($checkpwd);

	        $name     = I("numbers");
            $password = md5(I("password"));
            $temp     = M("admin")->where("numbers = '{$name}' and password = '{$password}'")->find();
            if(!$cd){
                $this->ajaxReturn(array("status"=>1));   //验证码不正确
            }

	    	if($temp){
	    	    if($temp['status'] == 2){
                    $this->ajaxReturn(array("status"=>4));    //管理员权限已被禁用
                }else{
                    $_SESSION['admin'] = $temp;
                    //登录日志
                    $content = "管理员：“{$temp['numbers']}” 于 ".date("Y-m-d H:i:s",time())."登录了后台";
                    $log     = ins("logs",array("content"=>$content,"admin_id"=>$temp['id'],"create_at"=>time()));
                    $this->ajaxReturn(array("status"=>2));    //ok
                }
            }else{
                $this->ajaxReturn(array("status"=>3));     //账号密码不正确
            }
	    }
        /**
         * 生成验证码
         */
        public function captcha() {
            $this->verify->useNoise = true;
            $this->verify->useCurve = false;
            $this->verify->imageW = 140;
            $this->verify->imageH = 34;
            $this->verify->length = 4;
            $this->verify->fontSize = 16;
            $this->verify->entry();
        }
	}